home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  7.5 KB  |  323 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     StdIO.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1991, 1993-1994.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14. /* Conditional Macros:
  15.  *    UsingStaticLibs    - for CFM-68K:  Insures that #pragma lib_export is never used.
  16.  *    UsingSharedLibs    - for CFM-68K:  Insures that all functions and data items are
  17.  *                                    marked as exported
  18.  *    <none>            - for CFM-68K:    Data items are exported using #pragma lib_export,
  19.  *                                    functions are not.  Causes excess code to be
  20.  *                                    generated for data references to static libraries
  21.  *                                    and causes the linker to generate glue for
  22.  *                                    references to shared library routines.
  23.  *    The preceeding macros may not both be defined in the same compilation.
  24.  */
  25. #if defined (UsingStaticLibs) && defined (UsingSharedLibs)
  26.     #error "Only one of the conditional macros 'UsingStaticLibs' and 'UsingSharedLibs' may be defined in a compilation"
  27. #endif
  28.  
  29. #ifndef __STDIO__
  30. #define __STDIO__
  31.  
  32. #ifndef NULL
  33. #define NULL 0
  34. #endif
  35.  
  36. #ifndef __size_t__
  37. #define __size_t__
  38. typedef unsigned int size_t;
  39. #endif
  40.  
  41. #ifndef __va_list__
  42. #define __va_list__
  43. typedef char *va_list;
  44. #endif
  45.  
  46.  
  47. /*
  48.  *    The basic data structure for a stream is the FILE.
  49.  */
  50.  
  51. #ifdef powerc
  52. #pragma options align=power
  53. #endif
  54. struct FILE {
  55.     int             _cnt;
  56.     unsigned char    *_ptr;
  57.     unsigned char    *_base;
  58.     unsigned char    *_end;
  59.     unsigned short    _size;
  60.     unsigned short    _flag;
  61.     unsigned short    _file;
  62. };
  63. #ifdef powerc
  64. #pragma options align=reset
  65. #endif
  66. typedef struct FILE FILE;
  67.  
  68.  
  69. /*
  70.  *    fpos_t is a type that can express any position in a file.  A file's
  71.  *    end-of-file marker has type fpos_t.
  72.  */
  73.  
  74. typedef long fpos_t;
  75.  
  76.  
  77. /*
  78.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  79.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  80.  */
  81.  
  82. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  83. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  84. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  85. #define _IONBF        (1<<2)        /* no buffering */
  86. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  87. #define _IOEOF        (1<<4)
  88. #define _IOERR        (1<<5)
  89. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  90. #define _IORW        (1<<7)        /* Enable read/write access */
  91. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  92. #define _IOBINARY    (1<<9)        /* Binary stream */
  93. #define _IOBACK        (1<<14)        /* Result of "ungetc() is in the buffer */ 
  94.  
  95.  
  96. /*
  97.  *    Default file buffer sizes used by setbuf() and setvbuf().
  98.  */
  99.  
  100. #define BUFSIZ    1024            /* default file buffer size */
  101. #define _LBFSIZ  254            /* Line buffer size */
  102.  
  103.  
  104. /*
  105.  *    The standard end-of-file indicator.
  106.  */
  107.  
  108. #define EOF        (-1)
  109.  
  110.  
  111. /*
  112.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  113.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  114.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  115.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  116.  *    of digits, all determined at runtime.
  117.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  118.  */
  119.  
  120. #define L_tmpnam    14
  121. #define TMP_MAX        17576
  122.  
  123.  
  124. /*
  125.  *    The minimum number of files that a program is guaranteed to be able to have
  126.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  127.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  128.  *    64K ROM, 128K Macintosh        12 files
  129.  *    64K ROM, 512K Macintosh        40 files
  130.  *    128K ROM                    40 files per volume
  131.  */
  132.  
  133. #define FOPEN_MAX    12
  134.  
  135.  
  136. /*
  137.  *    Maximum length of a file name, including a trailing zero byte.
  138.  */
  139.  
  140. #define FILENAME_MAX    32
  141.  
  142.  
  143. /*
  144.  *    For use by fseek():
  145.  */
  146.  
  147. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  148.  
  149. #define SEEK_CUR    1
  150. #define SEEK_END    2
  151. #define SEEK_SET    0
  152.  
  153. #endif
  154.  
  155.  
  156. /*
  157.  *    The standard predefined streams.
  158.  */
  159.  
  160. #define stdin        (&_iob[0])
  161. #define stdout        (&_iob[1])
  162. #define stderr        (&_iob[2])
  163.  
  164.  
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168.  
  169. #ifdef __CFM68K__
  170.     #ifdef UsingSharedLibs
  171.         #pragma lib_export on
  172.     #endif
  173. #endif
  174.  
  175. /*
  176.  *    Operations on files
  177.  */
  178.  
  179. int remove(const char *filename);
  180. int rename(const char *oldname, const char *newname);
  181. FILE *tmpfile(void);
  182. char *tmpnam(char *s);
  183.  
  184.  
  185. /*
  186.  *    File access functions
  187.  */
  188.  
  189. int fclose(FILE *stream);
  190. int fflush(FILE *stream);
  191. FILE *fopen(const char *filename, const char *mode);
  192. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  193. void setbuf(FILE *stream, char *buf);
  194. int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  195.  
  196.  
  197. /*
  198.  *    Formatted input/output functions
  199.  */
  200.  
  201. int fprintf(FILE *stream, const char *format, ...);
  202. int fscanf(FILE *stream, const char *format, ...);
  203. int printf(const char *format, ...);
  204. int scanf(const char *format, ...);
  205. int sprintf(char *s, const char *format, ...);
  206. int sscanf(const char *s, const char *format, ...);
  207. int vfprintf(FILE *stream, const char *format, va_list arg);
  208. int vprintf(const char *format, va_list arg);
  209. int vsprintf(char *s, const char *format, va_list arg);
  210.  
  211.  
  212. /*
  213.  *    Character input/output functions and macros
  214.  */
  215.  
  216. int fgetc(FILE *stream);
  217. char *fgets(char *s, int n, FILE *stream);
  218. int fputc(int c, FILE *stream);
  219. int fputs(const char *s, FILE *stream);
  220. int getc(FILE *stream);
  221. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  222. int getchar(void);
  223. #define getchar()    getc(stdin)
  224. char *gets(char *s);
  225. int putc(int c, FILE *stream);
  226. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  227.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  228.                         _flsbuf((unsigned char) (x), (p)))
  229. int putchar(int c);
  230. #define putchar(x)    putc((x), stdout)
  231. int puts(const char *s);
  232. int ungetc(int c, FILE *stream);
  233.  
  234.  
  235. /*
  236.  *    Direct input/output functions
  237.  */
  238.  
  239. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  240. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  241.  
  242.  
  243. /*
  244.  *    File positioning functions
  245.  */
  246.  
  247. int fgetpos(FILE *stream, fpos_t *pos);
  248. int fseek(FILE *stream, long int offset, int whence);
  249. int fsetpos(FILE *stream, const fpos_t *pos);
  250. long int ftell(FILE *stream);
  251. void rewind(FILE *stream);
  252.  
  253.  
  254. /*
  255.  *    Error-handling functions and macros
  256.  */
  257.  
  258. void clearerr(FILE *stream);
  259. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  260. int feof(FILE *stream);
  261. #define feof(p)     ((p)->_flag & _IOEOF)
  262. int ferror(FILE *stream);
  263. #define ferror(p)    ((p)->_flag & _IOERR)
  264. void perror(const char *s);
  265.  
  266. /*
  267.  * For macros
  268.  */
  269.  
  270. #ifdef __CFM68K__
  271.     #ifndef UsingStaticLibs
  272.         #pragma lib_export on
  273.     #endif
  274. #endif
  275.  
  276. extern FILE _iob[];
  277.  
  278. #ifdef __CFM68K__
  279.     #ifndef UsingSharedLibs
  280.         #pragma lib_export off
  281.     #endif
  282. #endif
  283.  
  284. #define _NFILE 40
  285. int _filbuf(FILE *);
  286. int _flsbuf(unsigned char, FILE *);
  287.  
  288. /*
  289.  *    Non-ANSI extensions
  290.  *
  291.  * The prefered mechanism for enabling these is by defining __useAppleExts__.  
  292.  * In the absence of this symbol, the __STDC__ symbol is used to enable or
  293.  * disable these extentions.
  294.  */
  295.  
  296. /* CFront can't handle the pretty version of this conditional 
  297. #if defined (__useAppleExts__) || \
  298.     ((defined (applec) && ! defined (__STDC__)) || \
  299.      (defined (__PPCC__) && __STDC__ == 0))
  300. */
  301. #if defined (__useAppleExts__) || ((defined (applec) && ! defined (__STDC__)) || (defined (__PPCC__) && __STDC__ == 0))
  302.  
  303. #define fileno(p)    (p)->_file
  304. FILE *fdopen(int fildes, const char *mode);
  305. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  306. int getw(FILE *stream);
  307. int putw(int w, FILE *stream);
  308.  
  309. #endif
  310.  
  311. #ifdef __CFM68K__
  312.     #ifdef UsingSharedLibs
  313.         #pragma lib_export off
  314.     #endif
  315. #endif
  316.  
  317. #ifdef __cplusplus
  318. }
  319. #endif
  320.  
  321.  
  322. #endif
  323.